package com.MovieManageSystem.controller;

import com.MovieManageSystem.domain.Feedback;
import com.MovieManageSystem.service.FeedbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin(origins = "*")
@RequestMapping("/api/feedbacks")
public class FeedbackController {

    @Autowired
    private FeedbackService feedbackService;

    // 提交反馈
    @PostMapping
    public ResponseEntity<Feedback> submitFeedback(@RequestBody Feedback feedback) {
        feedbackService.submitFeedback(feedback);
        return ResponseEntity.ok(feedback);
    }

    // 获取特定反馈
    @GetMapping("/{fid}")
    public ResponseEntity<Feedback> getFeedback(@PathVariable Integer fid) {
        Feedback feedback = feedbackService.getFeedbackById(fid);
        return ResponseEntity.ok(feedback);
    }

    // 获取所有反馈
    @GetMapping("/all")
    public ResponseEntity<List<Feedback>> getAllFeedbacks() {
        List<Feedback> feedbacks = feedbackService.getAllFeedbacks();
        return ResponseEntity.ok(feedbacks);
    }

    // 删除反馈
    @DeleteMapping("/{fid}")
    public ResponseEntity<Void> deleteFeedback(@PathVariable Integer fid) {
        feedbackService.deleteFeedbackByFid(fid);
        return ResponseEntity.noContent().build();
    }
}

